require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#modifyPrice",
    data:{
        loginUid:"",
        orderNumber:"",
        integral:"",   //总乐币
        freightIntegral:"",  //运费乐币
        productintegral:"",   //商品乐币
        orderInfo:{}
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.loginUid=this.searchObject&&this.searchObject.uid;
        this.orderNumber=this.searchObject&&this.searchObject.orderNumber;
        this.userOrderInfo();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //订单详情
        userOrderInfo:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                orderNumber:that.orderNumber
            };
            that.ajax({url:"/purchase/userOrderInfo",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.orderInfo=b.json.data;
                    that.productintegral=that.orderInfo.integral;
                    that.freightIntegral=that.orderInfo.freightIntegral;
                    that.integral=that.productintegral+that.freightIntegral;
                }else{
                    vm.$refs.prompt.toast("获取订单详情失败！");
                }
            });
        },
        //修改运费
        sellerupdateorderprice:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                orderNumber:that.orderNumber,
                integral:that.integral,   //总乐币
                freightIntegral:that.freightIntegral,  //运费乐币
                productintegral:that.productintegral   //商品乐币
            };
            that.ajax({url:"/happyi/sellerupdateorderprice",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getBack();
                }else{
                    vm.$refs.prompt.toast("修改失败！");
                }
            });
        }
    }
    ,watch:{
        freightIntegral:function(){
            this.integral=Number(this.productintegral)+Number(this.freightIntegral);
        },
        productintegral:function(){
            this.integral=Number(this.productintegral)+Number(this.freightIntegral);
        }
    }
});